package cn.com.lyj6851.modules.user.controller;

import cn.com.lyj6851.dozer.service.IGenerator;
import cn.com.lyj6851.logging.aop.AopLog;
import cn.com.lyj6851.modules.user.service.YdyUserRechargeService;
import cn.com.lyj6851.modules.user.service.dto.YdyUserRechargeDto;
import cn.com.lyj6851.modules.user.service.dto.YdyUserRechargeQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

@Api(tags = "充值管理管理")
@RestController
@RequestMapping("/api/ydyUserRecharge")
public class UserRechargeController {

    private final YdyUserRechargeService ydyUserRechargeService;
    private final IGenerator generator;
    public UserRechargeController(YdyUserRechargeService ydyUserRechargeService, IGenerator generator) {
        this.ydyUserRechargeService = ydyUserRechargeService;
        this.generator = generator;
    }

    @AopLog("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ydyUserRecharge:list')")
    public void download(HttpServletResponse response, YdyUserRechargeQueryCriteria criteria) throws IOException {
        ydyUserRechargeService.download(generator.convert(ydyUserRechargeService.queryAll(criteria), YdyUserRechargeDto.class), response);
    }

    @GetMapping
    @AopLog("查询充值管理")
    @ApiOperation("查询充值管理")
    @PreAuthorize("@el.check('ydyUserRecharge:list')")
    public ResponseEntity<Object> getYdyUserRecharges(YdyUserRechargeQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(ydyUserRechargeService.queryAll(criteria,pageable), HttpStatus.OK);
    }




    @AopLog("删除充值管理")
    @ApiOperation("删除充值管理")
    @PreAuthorize("@el.check('ydyUserRecharge:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
        ydyUserRechargeService.removeByIds(new ArrayList<>(Arrays.asList(ids)));
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
